<?php
$server="localhost";  // often something as mysql-5
$user="root";  // user name
$pass="";      // user password
$dbname="myaudiometer.com";   // the name of your database
$suffix = "aa_";


include_once("rss-class.php");

function makeUTF($desc)
{  
  $desc = UTF8_encode($desc);
  $desc = stripslashes($desc);
  return($desc);
} 

function isoToTime($iso) 
{
  sscanf($iso,"%4u-%2u-%2u %2u:%2u:%2u",$y,$mo,$d,$h,$m,$s);
  $t = mktime($h-2,$m,$s,$mo,$d,$y);
  return $t;
} 

$connexion = mysql_connect($server, $user, $pass);
if (!$connexion) die('Connect error: '.mysql_error());

$res = mysql_select_db($dbname); 
if(!$res) echo "$dbname not available<br>";

date_default_timezone_set('UTC');
// choose you format US/Other
// D, M d, Y - H:i:s
$date = date("D, d M Y H:i:s");  

$title="My Feed";
$url="http://www.xul.fr";
$desc="Feed of my site";

$myfeed = new Ara();
$myfeed->ARAFeed($title, $url, $desc, $date);	

$tablename = $suffix."posts";

$command="SELECT * FROM $tablename ORDER BY post_date DESC LIMIT 10";

$items  = mysql_query($command, $connexion);
if(!$items) die("Select error: ".mysql_error()); 

while($article = mysql_fetch_assoc($items))
{
    $title = makeUTF($article["post_title"]);
    //$url = $article["guid"];
    $desc = $article["post_content"];
    $desc = trim(substr($desc, 0, 128));
    $len = strlen($desc) -1;
    $x = strpos($desc, '<'); 
    if($x !== false && $x < $len) $len = $x;
    if($desc[$len] != ".")
    {
     while($len > 20 && ord($desc[$len]) != 32) $len--;
    }   
    $desc = trim(substr($desc, 0, $len)) . "...";
    
    $desc = makeUTF($desc);
    
    // choose you format US/Other
    // date("D, M d, Y H:i:s" 
    $date = date("D, d M Y H:i:s", isoToTime($article["post_date"]));  

		$myfeed->ARAItem($title, $url, $desc, $date." UTC");
}

// storing the file 

$myfeed->save("rss.xml");
 
echo '<br><a href="rss.xml"><img src="rss.gif" border=0 /></a><br>';
?>
